package logic

import (
	"context"
	"cp/cprpc/cprpcclient"

	"cp/api/internal/svc"
	"cp/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type EvaluationAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewEvaluationAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EvaluationAddLogic {
	return &EvaluationAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *EvaluationAddLogic) EvaluationAdd(req *types.EvaluationAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.CpRpc.EvaluationAdd(l.ctx, &cprpcclient.EvaluationAddRequest{
		CourseId:    int64(req.CourseId),
		UserId:      int64(req.UserId),
		Score:       req.Score,
		Content:     req.Content,
		IsAnonymous: req.IsAnonymous,
		Status:      req.Status,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "评价成功",
		Data:    add,
		Code:    200,
	}, nil

}
